<template>
	<view class="cunten">
		<view class="merchant-list" v-for="(item,index) in list" :key="index" @click="pathshop(item.id)">
			<view class="list-left">
				<image :src="item.logo" lazy-load="true" mode="" class="left-pic"></image><text>{{item.name}}</text>
			</view>
			<view class="list-right" v-if="item.isable">
				<u-icon name="checkbox-mark" color="#2979ff" size="40"></u-icon>
			</view>
		</view>
		<view class="merchant-list" @click="addmerchant">
			<view class="list-left">
				<image src="../../static/img/add.png" mode="" class="left-pic"></image><text>添加账号</text>
			</view>
			
		</view>
		<view class="btn">
			
			<button type="primary" @click="quit">安全退出</button>
		</view>
		
	</view>
</template>

<script>
	import store from '@/store/index.js'
	import {merchantlist} from "../../api/merchant/index.js"
	export default{
		data(){
			return{
				list:[
					{logo:require('../../static/img/dp.png'),name:"N多寿司",isable:true},
					{logo:require('../../static/img/hg.png'),name:"牛很鲜火锅",isable:false},
					
				]
			}
		},
		onLoad(){
			this.init()
		},
		methods:{
			// 安全退出
			quit(){
				uni.clearStorageSync();
				uni.reLaunch({
				   url:"/pages/login/login"
				});
			},
			// 门店选择
			//这个是商户id
			pathshop(el){
				console.log(el)
				uni.setStorageSync("addmerchantid",el)
				uni.navigateTo({
					url:'/pages/merchant/switchover?id=' + el
				})
			},
			addmerchant(){
				// 添加账号
				uni.navigateTo({
					url:"/pages/merchant/addmerchant"
				})
			},
			//拉取商户列表
			init(){
				const tokenlist =uni.getStorageSync('tokenlist');
				if(tokenlist){
					let obj={
						tel:tokenlist.tel,
						name:tokenlist.name,
						agent_id:"32",
						role:tokenlist.role,
						staff_id:tokenlist.staff_id,
					}
					merchantlist({...obj}).then(res=>{
						console.log(res)
						if(res.code==0){
							this.list=res.data
							
						}
					})
				}else{
					uni.reLaunch({
						url:"/pages/login/login"
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cunten{
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		align-items: center;
		width: 100%;
		
	}
	.merchant-list{
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 690rpx;
		padding: 30rpx;
		margin: 20rpx 0;
		background-color: #FFFFFF;
		.list-left{
			display: flex;
			align-items: center;
			font-size: 34rpx;
			font-weight: bold;
			.left-pic{
				background-color: #E9E9E9;
				border-radius: 50%;
				width:100rpx ;
				height: 100rpx;
				margin-right: 20rpx;
			}
		}
	}
	.btn{
		position: fixed;
		bottom: 80rpx;
		left: 75rpx;
		width: 600rpx;
		height: 100rpx;
		border-radius: 54rpx;
		button{
			border-radius: 54rpx;
		}
	}
</style>
